import { useState, useEffect } from 'react';
import { Entypo } from '@expo/vector-icons';
import { AntDesign } from '@expo/vector-icons';
import { FlatList, StyleSheet, TouchableOpacity, Text, Button, View, Image, TextInput, ScrollView } from 'react-native';

const AddAddress = ({ navigation }) => {
    const onBtn = () => {
        fetch('http://10.7.89.170:3000/befoAddAddress',
            {
                method: 'POST',
                body: JSON.stringify({
                    userName1: user.userName,
                    addressName: addressName,
                    phoneNum: phoneNum,
                    park: park,
                    building: building
                })
            })
            .then(res => res.json())
            .then(res => {
                console.log(res)
                navigation.navigate('DeliveryAddress')
            })
    }
    const [userName, setuserName] = useState("");
    const [addressName, setaddressName] = useState("");
    const [phoneNum, setphoneNum] = useState("");
    const [park, setpark] = useState("");
    const [building, setbuilding] = useState("");
    return (
        <View style={{ flex: 1 }}>
            <ImageBackground source={require('../img/bgimg.jpg')} style={styles.bgimg}>
                <View style={{ width: "90%", marginLeft: "5%", marginTop: 30 }}>
                    <View style={{ marginTop: 30 }}>
                        <Text style={{ marginLeft: "10%" }}>用户名</Text>
                        <TextInput
                            placeholder="单行输入"
                            value={userName}
                            onChangeText={(value) => setuserName(value)}
                            style={{ height: 40, width: "55%", borderColor: 'grey', borderWidth: 1, marginLeft: "35%", marginTop: "-7%" }}
                        />
                    </View>
                    <View style={{ marginTop: 30 }}>
                        <Text style={{ marginLeft: "10%" }}>收货人</Text>
                        <TextInput
                            placeholder="单行输入"
                            value={addressName}
                            onChangeText={(value) => setaddressName(value)}
                            style={{ height: 40, width: "55%", borderColor: 'grey', borderWidth: 1, marginLeft: "35%", marginTop: "-7%" }}
                        />
                    </View>
                    <View style={{ marginTop: 30 }}>
                        <Text style={{ marginLeft: 40 }}>电话号码</Text>
                        <TextInput
                            placeholder="单行输入"
                            value={phoneNum}
                            onChangeText={(value) => setphoneNum(value)}
                            style={{ height: 40, width: "55%", borderColor: 'grey', borderWidth: 1, marginLeft: "35%", marginTop: "-7%" }}
                        />
                    </View>
                    <View style={{ marginTop: 30 }}>
                        <Text style={{ marginLeft: 40 }}>园       区</Text>
                        <TextInput
                            placeholder="单行输入"
                            value={park}
                            onChangeText={(value) => setpark(value)}
                            style={{ height: 40, width: "55%", borderColor: 'grey', borderWidth: 1, marginLeft: "35%", marginTop: "-7%" }}
                        />
                    </View>
                    <View style={{ marginTop: 30 }}>
                        <Text style={{ marginLeft: 40 }}>楼       号</Text>
                        <TextInput
                            placeholder="单行输入"
                            value={building}
                            onChangeText={(value) => setbuilding(value)}
                            style={{ height: 40, width: "55%", borderColor: 'grey', borderWidth: 1, marginLeft: "35%", marginTop: "-7%" }}
                        />
                    </View>
                </View>
                <View style={{ width: 200, marginLeft: 125, marginTop: 40 }}>
                    <Button
                        title="保存"
                        onPress={() => onBtn()}
                    />
                </View>
            </ImageBackground>
        </View>
    );
}

const styles = StyleSheet.create({
    bgimg: {
        flex: 1,
        resizeMode: "cover",
    },
});

export default AddAddress 